#!/bin/bash
set -e

errinfo=""

ulimit -c 500000
echo '' > result
for t in `ls test/gtest_unit/*.t`
do
    echo ''
    echo ------------ run $t -------------- | tee -a result
    ./$t | tee -a result | tee run_test_tmp
    if [ "$?" != "0" ]
    then
        echo $t " was FAILED."
        exit 2
    fi
    echo ---------------------------------- | tee -a result

    failed=`grep "^\[\s*FAILED" run_test_tmp | wc -l`
    if [ $failed -gt 0 ];
    then
        errinfo+=" -> `basename $t` run error\n"
    fi
done

if test -z "$errinfo"
then
    echo "all test were PASSED:"
    echo -e "$errinfo"
    exit 0
else
    echo "some test were FAIL:"
    echo -e "$errinfo"
    exit 1
fi
